home *** CD-ROM | disk | FTP | other *** search
- /* File: ControlKeyTest.c
-
- Description:
- routines for patching the ADB manager to simulate the control
- key being held down. This file contains a simple application that
- installs the control key patch and allows users to turn it on and off.
-
- Author: John Montbriand
-
- Copyright:
- Copyright © 1999 by Apple Computer, Inc.
- All rights reserved worldwide.
-
- Disclaimer:
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- Change History (most recent first):
- 27/8/99 created by John Montbriand
- */
-
- #include <Types.h>
- #include <QuickDraw.h>
- #include <Menus.h>
- #include <Windows.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <SegLoad.h>
- #include <Resources.h>
- #include <Gestalt.h>
- #include <Appearance.h>
-
- #include "ControlKeyPatch.h"
-
- /* true while the app is running */
- Boolean gRunning = true;
-
- /* true while the app is in forground */
- Boolean gForground = true;
-
- /* true while the control key is locked down */
- Boolean gLocked = false;
-
- /* a pointer to the patch - type defined in ControlKeyPatch.h*/
- ControlKeyPatchPtr gPatch = NULL;
-
- /* QuickDraw globals*/
- #ifndef __MWERKS__
- QDGlobals qd;
- #endif
- Boolean gAppearance = false;
-
- int main(void) {
- OSErr err;
- ControlHandle lockControl;
- DialogPtr mainDialog;
- long response;
- /* set up our app */
- SetApplLimit(GetApplLimit());
- MaxApplZone();
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- TEInit();
- InitMenus();
- InitDialogs(0);
- FlushEvents(everyEvent, 0);
- InitCursor();
- if (Gestalt(gestaltAppearanceAttr, &response) != noErr) response = 0;
- if ((response & (1<<gestaltAppearanceExists)) != 0) {
- err = RegisterAppearanceClient();
- if (err != noErr) goto bail;
- gAppearance = true;
- }
-
- /* set up the dialog */
- mainDialog = GetNewDialog(128, NULL, (WindowPtr) (-1));
- { short itemt;
- Rect itemb;
- GetDialogItem(mainDialog, 1, &itemt, (Handle*) &lockControl, &itemb);
- }
-
- /* install the patch */
- err = NewControlKeyPatch(false, &gPatch);
- if (err != noErr) goto bail;
-
- /* run the app */
- while (gRunning) {
- EventRecord ev;
- DialogPtr theDialog;
- WindowPtr theWindow;
- short itemNo;
-
- /* get the next event */
- if ( ! WaitNextEvent(everyEvent, &ev, GetCaretTime(), NULL))
- ev.what = nullEvent;
- /* track forground switches */
- if ((ev.what == osEvt) && (((ev.message >> 24) & 0x0FF) == suspendResumeMessage)) {
- gForground = ((ev.message & resumeFlag) != 0);
- DrawDialog(mainDialog);
- HiliteControl(lockControl, gForground ? 0 : 255);
- }
- /* redraw if we're activating */
- if (ev.what == activateEvt) {
- DrawDialog(mainDialog);
- HiliteControl(lockControl, ((ev.modifiers & activeFlag) != 0) ? 0 : 255);
- }
- /* handle clicks in the dialog window */
- if (IsDialogEvent(&ev))
- if (DialogSelect(&ev, &theDialog, &itemNo)) {
- gLocked = ! gLocked;
- SetControlValue(lockControl, (gLocked ? 1 : 0));
- if (gLocked)
- SetControlKeyDown(gPatch);
- else SetControlKeyUp(gPatch);
- }
- /* process other window commands */
- if (ev.what == mouseDown)
- switch (FindWindow(ev.where, &theWindow)) {
-
- /* clicks in the close box, close the app */
- case inGoAway:
- if (TrackGoAway(theWindow, ev.where))
- gRunning = false;
- break;
-
- /* allow window drags */
- case inDrag:
- { Rect boundsRect = { -32000, -32000, 32000, 32000};
- DragWindow(theWindow, ev.where, &boundsRect);
- }
- break;
-
- /* desktop clicks, etc... */
- case inSysWindow:
- SystemClick(&ev, theWindow);
- break;
- }
- }
-
- bail:
- if (gPatch != NULL) DisposeControlKeyPatch(gPatch);
- if (gAppearance)
- UnregisterAppearanceClient();
- ExitToShell();
- return 0;
- }